import networkx as nx
import matplotlib.pyplot as plt
# 创建一个无向图
G = nx.Graph()
# 添加节点
G.add_node(1)
G.add_node(2)
G.add_node(3)
G.add_node(4)
G.add_node(5)
# 在节点1和节点2之间添加多条边，并为每条边指定一个唯一的键
G.add_edge(1, 2, )
G.add_edge(1,5, )
G.add_edge(2, 1, )
G.add_edge(2,3, )
G.add_edge(3, 2, )
G.add_edge(3,4, )
G.add_edge(4,3, )
G.add_edge(4,5, )
G.add_edge(5,4, )
G.add_edge(5,1, )
# 绘制无向图
pos = nx.spring_layout(G)  # 生成一个布局
nx.draw(G, pos, with_labels=True, edge_color='gray', width=1.0, alpha=0.5)
# 绘制边的键
edge_labels = nx.get_edge_attributes(G, 'key')
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)
# 显示图形
plt.show()